/* Copyright (c) 2009, Michael Patraw
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * The name of Michael Patraw may not be used to endorse or promote
 *       products derived from this software without specific prior written
 *       permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Michael Patraw ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Michael Patraw BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef PLAYER_H
#define PLAYER_H

#include <stdbool.h>

struct board_t;

/* The player structure.
 */
typedef struct player_t {
    struct board_t * board;
    const char * name;
    int controller;
    int x, y; /* Location on the map. */
    int team;
    int num_imm_objects; /* Number of immovable objects. */
    /* Used internally. */
    struct player_t * _next_player; /* Turn sequence. */
} player_t;

/* List of teams.
 */
enum {
    BLUE_TEAM,
    GREEN_TEAM
};

/* Creates a new player.
 */
extern player_t * Player_Create(struct board_t * board, int x, int y, int team,
        const char * name, int controller);

/* Destroys player.
 */
extern void Player_Destroy(player_t * player);

/* Destroy all players.
 */
extern void Player_DestroyAll(void);

/* This player loses, removed from the turn sequence.
 */
extern void Player_Loses(player_t * player, const char * reason);

/* Checks if the current player lost.
 */
extern bool Player_CheckIfCurrentLost(void);

/* Draws the player.
 */
extern void Player_Draw(player_t * player, unsigned int win_id);

/* Draws all the players in the turn sequence.
 */
extern void Player_DrawEveryone(unsigned int win_id);

/* Moves the player by a certain amount. Returns false if can't be moved there.
 */
extern bool Player_MoveBy(player_t * player, int dx, int dy);

/* Teleports the player. Returns false if can't be moved there.
 */
extern bool Player_MoveTo(player_t * player, int x, int y);

/* Moves the current player by a certain amount. Returns false if can't be
 * moved there.
 */
extern bool Player_CurrentMoveBy(int dx, int dy);

/* Teleports the current player. Returns false if can't be moved there.
 */
extern bool Player_CurrentMoveTo(int x, int y);

/* Returns false if it couldn't place the object.
 */
extern bool Player_PlaceObject(player_t * player, int x, int y);

/* Returns false if it couldn't place the object.
 */
extern bool Player_PlaceImmovableObject(player_t * player, int x, int y);

/* Asks the player for a location and if it's viable returns true after
 * placing it.
 */
extern bool Player_CurrentPlaceObject(void);

/* Asks the player for a location and if it's viable returns true after
 * placing it.
 */
extern bool Player_CurrentPlaceImmovableObject(void);

/* Sets a player to be part of the turn sequence. Shouldn't go over four
 * players.
 */
extern void Player_AddToTurnSequence(player_t * player);

/* Removes a player from the turn sequence.
 */
extern void Player_RemoveFromTurnSequence(player_t * player);

/* Removes all players from the turn sequence.
 */
extern void Player_ClearTurnSequence(void);

/* Gets the player thats next in the turn sequence.
 */
extern player_t * Player_NextTurn(void);

/* Checks if the player is the first player.
 */
extern bool Player_IsFirst(player_t * player);

/* Checks if the player is the last player.
 */
extern bool Player_IsLast(player_t * player);

/* Checks if it's currently the players turn.
 */
extern bool Player_IsTurn(player_t * player);

/* Returns true if the current play is an AI.
 */
extern bool Player_CurrentIsAi(void);

/* Draws the information for the players, like whos turn it is and how
 * many immovable objects they have left. Requires a Decently long window
 * with a height of at least two. **Information taken from players in turn
 * sequence**
 */
extern void Player_DrawInformation(unsigned int win_id);

#endif /* PLAYER_H */
